package com.luoran.bartalks.action;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.luoran.bartalks.action.vo.CompanyTemplateData;
import com.luoran.bartalks.core.UserContext;
import com.luoran.bartalks.entity.biz.BtCodingRule;
import com.luoran.bartalks.entity.biz.BtContainerTemplate;
import com.luoran.bartalks.entity.biz.BtPlanTemplate;
import com.luoran.bartalks.entity.biz.BtPosition;
import com.luoran.bartalks.entity.biz.BtRegion;
import com.luoran.bartalks.entity.biz.BtTransportMode;
import com.luoran.bartalks.entity.biz.CompanyInfo;
import com.luoran.bartalks.service.IBtCodingRuleService;
import com.luoran.bartalks.service.IBtContainerTemplateService;
import com.luoran.bartalks.service.IBtInitBasicInfoService;
import com.luoran.bartalks.service.IBtPlanTemplateService;
import com.luoran.bartalks.service.IBtPositionService;
import com.luoran.bartalks.service.IBtRegionService;
import com.luoran.bartalks.service.IBtTransportModeService;
import com.luoran.bartalks.service.ICompanyService;
import com.luoran.bartalks.utils.EnumBillType;

/**
 * 通用的公司基本信息初始化操作.理论上仅供平台方管理员使用
 * 
 * @author WMM 2018 2018年4月26日
 *
 */
@Controller
@RequestMapping("/init")
public class BtInitBasicInfoAction {

	@Value("${Stencil.CompanyId}")
	private String StencilCompanyId;

	@Autowired
	private ICompanyService companyService;

	@Autowired
	private IBtCodingRuleService codingRuleService;

	@Autowired
	private IBtContainerTemplateService containerTemplateService;

	@Autowired
	private IBtTransportModeService transportService;

	@Autowired
	private IBtPlanTemplateService planTemplateService;

	@Autowired
	private IBtRegionService regionService;

	@Autowired
	private IBtPositionService positionService;

	@Autowired
	private IBtInitBasicInfoService initBasicInfoService;

	private final static Logger log = LoggerFactory.getLogger(BtInitBasicInfoAction.class);

	@RequestMapping
	public String init(Model model) {
		// 当前为模版公司将不可以操作 是admin公司 多选操作 非admin为固定公司操作
		JSONObject CompanyType = new JSONObject();
		String CompanyId = UserContext.get().getCompanyId();
		if (StencilCompanyId.equals(CompanyId)) {
			CompanyType.put("tag", true);
			CompanyType.put("type", "stencil");
			model.addAttribute("stencilCompanyId", StencilCompanyId);
		} else {
			CompanyType.put("tag", false);
			if ("-1".equals(CompanyId)) {
				CompanyType.put("type", "admin");
				// 获取公司列表
				List<CompanyInfo> companys = companyService.getCompanyList();
				model.addAttribute("companys", companys);
			} else {
				CompanyType.put("type", "user");
				JSONObject currentCompany = new JSONObject();
				currentCompany.put("currentCompanyName", UserContext.get().getCompanyName());
				currentCompany.put("currentCompanyId", UserContext.get().getCompanyId());
				model.addAttribute("currentCompany", currentCompany);
			}
		}
		model.addAttribute("CompanyType", CompanyType);
		// 获取模版公司数据
		List<BtCodingRule> codingRules = codingRuleService.getcodingRuleStencilList(StencilCompanyId);
		model.addAttribute("codingRules", codingRules);
		List<BtContainerTemplate> containerTemplates = containerTemplateService
				.getContainerTemplateStencilList(StencilCompanyId);
		model.addAttribute("containerTemplates", containerTemplates);
		List<BtTransportMode> transportModes = transportService.getTransportModeStencilList(StencilCompanyId);
		model.addAttribute("transports", transportModes);
		List<BtPlanTemplate> planTemplates = planTemplateService.getPlanTemplateStencilList(StencilCompanyId);
		model.addAttribute("planTemplates", planTemplates);
		log.info("跳转至公司资料初始化页面>>>");
		return "systemManage/init";
	}

	@RequestMapping("data/import")
	@ResponseBody
	public JSONObject dataImport(@RequestBody CompanyTemplateData companyTemplateData) {
		JSONObject result = new JSONObject();
		if (companyTemplateData.getCompany().size() == 0) {
			result.put("state", false);
			result.put("msg", "数据异常!");
			return result;
		}
		JSONObject stencilCompanyDataImput = initBasicInfoService.StencilCompanyDataImput(companyTemplateData, StencilCompanyId);
		if(stencilCompanyDataImput.get("state").equals(true)) {
			result.put("state", true);
		}else {
			result.put("state", false);
			result.put("msg", stencilCompanyDataImput.get("msg"));
		}
		return result;
	}

	/**
	 * 获取菜单树
	 * 
	 * @return
	 */
	@RequestMapping("/regionTree")
	@ResponseBody
	public JSONObject getRegionTree() {
		log.info("获取区域菜单树>>>>>>>");
		JSONObject result = new JSONObject();
		List<JSONObject> treeData = new ArrayList<>();// 保存树信息
		List<BtRegion> regionTree = regionService.getTreeList(StencilCompanyId);

		if (regionTree == null) {
			result.put("flag", false);
			result.put("obj", "获取菜单树失败");
			log.info("获取菜单树失败<<<<<");
			return result;
		} else if (regionTree.size() == 0) {
			result.put("flag", false);
			result.put("obj", "模板公司暂无数据");
			log.info("模板公司暂无数据<<<<<");
			return result;
		}
		// 遍历集合,把菜单封装到JSON格式的集合
		for (int i = 0; i < regionTree.size(); i++) {
			JSONObject obj = new JSONObject();
			obj.put("code", regionTree.get(i).getRegionCode());
			obj.put("menuName", regionTree.get(i).getRegionName());
			obj.put("parentCode", regionTree.get(i).getParentRegCode());
			treeData.add(obj);
		}

		/*
		 * // 遍历菜单树和用户菜单,获取已拥有菜单.添加checked属性 for (int i = 0; i < treeData.size(); i++) {
		 * for (int j = 0; j < regionTree.size(); j++) { if
		 * ((treeData.get(i).getString("id")).equals(userMenus.get(j).getMenuId())) {
		 * treeData.get(i).put("checked", true);// 再给json添加一个key } } }
		 */
		result.put("flag", true);
		result.put("obj", treeData);
		return result;

	}

	/**
	 * 查询所有对应区域列表的位置信息
	 * 
	 * @return
	 */
	@RequestMapping("/getPostions")
	@ResponseBody
	public JSONObject getPostions(@RequestParam(value = "codeList") String[] regionCodes) {
		JSONObject res = new JSONObject();
		List<BtPosition> BtPositions = positionService.getPositsByReigs(regionCodes, StencilCompanyId);
		if (!BtPositions.isEmpty()) {
			res.put("positions", BtPositions);
			res.put("state", true);
		} else {
			res.put("msg", "暂无数据！");
			res.put("state", false);
		}
		return res;
	}

	/**
	 * 模板公司的数据初始化
	 * 
	 * @param companyId
	 * @return
	 */
	@RequestMapping("/generate")
	@ResponseBody
	public JSONObject generateBasicInfo(@RequestParam(value = "companyId") String companyId) {
		JSONObject res = new JSONObject();
		if (!StencilCompanyId.equals(UserContext.get().getCompanyId())) {
			res.put("flag", false);
			res.put("msg", "非法操作!");
			return res;
		}
		List<BtCodingRule> codingRules = new ArrayList<>();
		List<BtContainerTemplate> templates = new ArrayList<>();
		List<BtTransportMode> transportModes = new ArrayList<>();
		List<BtRegion> regions = new ArrayList<>();
		// 编码生成规则对象
		BtCodingRule codingRule1 = new BtCodingRule();
		BtCodingRule codingRule2 = new BtCodingRule();
		BtCodingRule codingRule3 = new BtCodingRule();
		BtCodingRule codingRule4 = new BtCodingRule();
		BtCodingRule codingRule5 = new BtCodingRule();
		BtCodingRule codingRule6 = new BtCodingRule();
		BtCodingRule codingRule7 = new BtCodingRule();
		BtCodingRule codingRule8 = new BtCodingRule();
		BtCodingRule codingRule9 = new BtCodingRule();
		// 容器模板对象
		BtContainerTemplate template1 = new BtContainerTemplate();
		BtContainerTemplate template2 = new BtContainerTemplate();
		BtContainerTemplate template3 = new BtContainerTemplate();
		BtContainerTemplate template4 = new BtContainerTemplate();
		BtContainerTemplate template5 = new BtContainerTemplate();
		// 运输方式
		BtTransportMode transportMode1 = new BtTransportMode();
		BtTransportMode transportMode2 = new BtTransportMode();
		BtTransportMode transportMode3 = new BtTransportMode();

		// 区域对象
		BtRegion region1 = new BtRegion();
		BtRegion region2 = new BtRegion();
		BtRegion region3 = new BtRegion();
		BtRegion region4 = new BtRegion();
		BtRegion region5 = new BtRegion();
		BtRegion region6 = new BtRegion();
		BtRegion region7 = new BtRegion();
		BtRegion region8 = new BtRegion();
		BtRegion region9 = new BtRegion();
		BtRegion region10 = new BtRegion();
		BtRegion region11 = new BtRegion();
		BtRegion region12 = new BtRegion();
		BtRegion region13 = new BtRegion();
		BtRegion region14 = new BtRegion();
		BtRegion region15 = new BtRegion();
		BtRegion region16 = new BtRegion();
		BtRegion region17 = new BtRegion();
		BtRegion region18 = new BtRegion();
		BtRegion region19 = new BtRegion();
		BtRegion region20 = new BtRegion();
		BtRegion region21 = new BtRegion();
		BtRegion region22 = new BtRegion();
		BtRegion region23 = new BtRegion();
		BtRegion region24 = new BtRegion();
		BtRegion region25 = new BtRegion();
		BtRegion region26 = new BtRegion();
		BtRegion region27 = new BtRegion();
		BtRegion region28 = new BtRegion();
		BtRegion region29 = new BtRegion();
		BtRegion region30 = new BtRegion();
		BtRegion region31 = new BtRegion();
		BtRegion region32 = new BtRegion();
		BtRegion region33 = new BtRegion();
		BtRegion region34 = new BtRegion();

		// 设置值
		codingRule1.setCompanyId(companyId);// 公司ID
		codingRule1.setSequenceLength(5);// 序列长度
		codingRule1.setSequenceBeginValue(0);// 起步值
		codingRule1.setStepLengthValue(1);// 步长值
		codingRule1.setCreateTime(new Date());// 创建日期
		codingRule1.setRuleStatus(0);// 状态
		codingRule1.setRuleDesc("初始化区域编码生成规则");
		codingRule1.setBillType(EnumBillType.AREA.getName());// 区域
		codingRule1.setCodingPrefix("QY-");// 区域编码前缀
		codingRules.add(codingRule1);

		codingRule2.setCompanyId(companyId);// 公司ID
		codingRule2.setSequenceLength(5);// 序列长度
		codingRule2.setSequenceBeginValue(0);// 起步值
		codingRule2.setStepLengthValue(1);// 步长值
		codingRule2.setCreateTime(new Date());// 创建日期
		codingRule2.setRuleStatus(0);// 状态
		codingRule2.setRuleDesc("初始化位置编码生成规则");
		codingRule2.setBillType(EnumBillType.POSITION.getName());// 位置
		codingRule2.setCodingPrefix("WZ-");// 位置编码前缀
		codingRules.add(codingRule2);

		codingRule3.setCompanyId(companyId);// 公司ID
		codingRule3.setSequenceLength(5);// 序列长度
		codingRule3.setSequenceBeginValue(0);// 起步值
		codingRule3.setStepLengthValue(1);// 步长值
		codingRule3.setCreateTime(new Date());// 创建日期
		codingRule3.setRuleStatus(0);// 状态
		codingRule3.setRuleDesc("初始化容器编码生成规则");
		codingRule3.setBillType(EnumBillType.CONTAINER.getName());// 容器
		codingRule3.setCodingPrefix("RQ-");// 容器编码前缀
		codingRules.add(codingRule3);

		codingRule4.setCompanyId(companyId);// 公司ID
		codingRule4.setSequenceLength(5);// 序列长度
		codingRule4.setSequenceBeginValue(0);// 起步值
		codingRule4.setStepLengthValue(1);// 步长值
		codingRule4.setCreateTime(new Date());// 创建日期
		codingRule4.setRuleStatus(0);// 状态
		codingRule4.setRuleDesc("初始化容器模板编码生成规则");
		codingRule4.setBillType(EnumBillType.CONTAINERTEMPLATE.getName());// 容器模板
		codingRule4.setCodingPrefix("RQMB-");// 容器模板编码前缀
		codingRules.add(codingRule4);

		codingRule5.setCompanyId(companyId);// 公司ID
		codingRule5.setSequenceLength(5);// 序列长度
		codingRule5.setSequenceBeginValue(0);// 起步值
		codingRule5.setStepLengthValue(1);// 步长值
		codingRule5.setCreateTime(new Date());// 创建日期
		codingRule5.setRuleStatus(0);// 状态
		codingRule5.setRuleDesc("初始化运输方式编码生成规则");
		codingRule5.setBillType(EnumBillType.TRANSPORTMETHOD.getName());// 运输方式
		codingRule5.setCodingPrefix("YSFS-");// 区域编码前缀
		codingRules.add(codingRule5);

		codingRule6.setCompanyId(companyId);// 公司ID
		codingRule6.setSequenceLength(5);// 序列长度
		codingRule6.setSequenceBeginValue(0);// 起步值
		codingRule6.setStepLengthValue(1);// 步长值
		codingRule6.setCreateTime(new Date());// 创建日期
		codingRule6.setRuleStatus(0);// 状态
		codingRule6.setRuleDesc("初始化计划模板编码生成规则");
		codingRule6.setBillType(EnumBillType.PLANTEMPLATE.getName());// 计划模板
		codingRule6.setCodingPrefix("JHMB-");// 计划模板编码前缀
		codingRules.add(codingRule6);

		codingRule7.setCompanyId(companyId);// 公司ID
		codingRule7.setSequenceLength(5);// 序列长度
		codingRule7.setSequenceBeginValue(0);// 起步值
		codingRule7.setStepLengthValue(1);// 步长值
		codingRule7.setCreateTime(new Date());// 创建日期
		codingRule7.setRuleStatus(0);// 状态
		codingRule7.setRuleDesc("初始化项目编码生成规则");
		codingRule7.setBillType(EnumBillType.PROJECT.getName());// 项目
		codingRule7.setCodingPrefix("XM-");// 项目编码前缀
		codingRules.add(codingRule7);

		codingRule8.setCompanyId(companyId);// 公司ID
		codingRule8.setSequenceLength(5);// 序列长度
		codingRule8.setSequenceBeginValue(0);// 起步值
		codingRule8.setStepLengthValue(1);// 步长值
		codingRule8.setCreateTime(new Date());// 创建日期
		codingRule8.setRuleStatus(0);// 状态
		codingRule8.setRuleDesc("初始化计划编码生成规则");
		codingRule8.setBillType(EnumBillType.PLAN.getName());// 计划
		codingRule8.setCodingPrefix("JH-");// 区域编码前缀
		codingRules.add(codingRule8);

		codingRule9.setCompanyId(companyId);// 公司ID
		codingRule9.setSequenceLength(5);// 序列长度
		codingRule9.setSequenceBeginValue(0);// 起步值
		codingRule9.setStepLengthValue(1);// 步长值
		codingRule9.setCreateTime(new Date());// 创建日期
		codingRule9.setRuleStatus(0);// 状态
		codingRule9.setRuleDesc("初始化箱单编码生成规则");
		codingRule9.setBillType(EnumBillType.PACKINGLIST.getName());// 箱单
		codingRule9.setCodingPrefix("QY-");// 区域编码前缀
		codingRules.add(codingRule9);

		template1.setTemplateCode("RQMB001");
		template1.setTemplateName("8吨货车");
		template1.setTemplateType(1);// 运输容器
		template1.setLongs(new BigDecimal(420));
		template1.setWide(new BigDecimal(190));
		template1.setHigh(new BigDecimal(180));
		template1.setDeadWeight(new BigDecimal(3000));// 自重
		template1.setBearWeight(new BigDecimal(8000));// 承重
		template1.setCompanyId(companyId);
		template1.setCreatTime(new Date());
		templates.add(template1);

		template2.setTemplateCode("RQMB002");
		template2.setTemplateName("20吨货车");
		template2.setTemplateType(1);// 运输容器
		template2.setLongs(new BigDecimal(1200));
		template2.setWide(new BigDecimal(240));
		template2.setHigh(new BigDecimal(270));
		template2.setDeadWeight(new BigDecimal(5000));// 自重
		template2.setBearWeight(new BigDecimal(20000));// 承重
		template2.setCompanyId(companyId);
		template2.setCreatTime(new Date());
		templates.add(template2);

		template3.setTemplateCode("RQMB003");
		template3.setTemplateName("20尺集装箱");
		template3.setTemplateType(1);// 运输容器
		template3.setLongs(new BigDecimal(589.8));
		template3.setWide(new BigDecimal(235.2));
		template3.setHigh(new BigDecimal(238.5));
		template3.setDeadWeight(new BigDecimal(2300));// 自重
		template3.setBearWeight(new BigDecimal(24000));// 承重
		template3.setCompanyId(companyId);
		template3.setCreatTime(new Date());
		templates.add(template3);

		template4.setTemplateCode("RQMB004");
		template4.setTemplateName("40尺集装箱");
		template4.setTemplateType(1);// 运输容器
		template4.setLongs(new BigDecimal(1235.8));
		template4.setWide(new BigDecimal(235.2));
		template4.setHigh(new BigDecimal(238.5));
		template4.setDeadWeight(new BigDecimal(3400));// 自重
		template4.setBearWeight(new BigDecimal(38000));// 承重
		template4.setCompanyId(companyId);
		template4.setCreatTime(new Date());
		templates.add(template4);

		template5.setTemplateCode("RQMB005");
		template5.setTemplateName("仓库");
		template5.setTemplateType(0);// 运输容器
		template5.setLongs(new BigDecimal(10000));
		template5.setWide(new BigDecimal(20000));
		template5.setHigh(new BigDecimal(500));
		template5.setBearWeight(new BigDecimal(1000000));// 承重
		template5.setCompanyId(companyId);
		template5.setCreatTime(new Date());
		templates.add(template5);

		transportMode1.setTransportCode("YSFS001");
		transportMode1.setCompanyId(companyId);
		transportMode1.setTransportChineseName("汽车运输");
		transportMode1.setTransportEnglishName("car");
		transportMode1.setCreateTime(new Date());
		transportMode1.setState(0);
		transportModes.add(transportMode1);

		transportMode2.setTransportCode("YSFS002");
		transportMode2.setCompanyId(companyId);
		transportMode2.setTransportChineseName("火车运输");
		transportMode2.setTransportEnglishName("train");
		transportMode2.setCreateTime(new Date());
		transportMode2.setState(0);
		transportModes.add(transportMode2);

		transportMode3.setTransportCode("YSFS003");
		transportMode3.setCompanyId(companyId);
		transportMode3.setTransportChineseName("轮船运输");
		transportMode3.setTransportEnglishName("ship");
		transportMode3.setCreateTime(new Date());
		transportMode3.setState(0);
		transportModes.add(transportMode3);

		region1.setCompanyId(companyId);
		region1.setRegionName("北京市");
		region1.setRegionCode("QY0001");
		region1.setState(1);
		region1.setCreateTime(new Date());
		region1.setLongCode("QY0001");
		regions.add(region1);

		region2.setCompanyId(companyId);
		region2.setRegionName("天津市");
		region2.setRegionCode("QY0002");
		region2.setState(1);
		region2.setCreateTime(new Date());
		region2.setLongCode("QY0002");
		regions.add(region2);

		region3.setCompanyId(companyId);
		region3.setRegionName("河北省");
		region3.setRegionCode("QY0003");
		region3.setState(1);
		region3.setCreateTime(new Date());
		region3.setLongCode("QY0003");
		regions.add(region3);

		region4.setCompanyId(companyId);
		region4.setRegionName("山西省");
		region4.setRegionCode("QY0004");
		region4.setState(1);
		region4.setCreateTime(new Date());
		region4.setLongCode("QY0004");
		regions.add(region4);

		region5.setCompanyId(companyId);
		region5.setRegionName("内蒙古自治区");
		region5.setRegionCode("QY0005");
		region5.setState(1);
		region5.setCreateTime(new Date());
		region5.setLongCode("QY0005");
		regions.add(region5);

		region6.setCompanyId(companyId);
		region6.setRegionName("辽宁省");
		region6.setRegionCode("QY0006");
		region6.setState(1);
		region6.setCreateTime(new Date());
		region6.setLongCode("QY0006");
		regions.add(region6);

		region7.setCompanyId(companyId);
		region7.setRegionName("吉林省");
		region7.setRegionCode("QY0007");
		region7.setState(1);
		region7.setCreateTime(new Date());
		region7.setLongCode("QY0007");
		regions.add(region7);

		region8.setCompanyId(companyId);
		region8.setRegionName("黑龙江省");
		region8.setRegionCode("QY0008");
		region8.setState(1);
		region8.setCreateTime(new Date());
		region8.setLongCode("QY0008");
		regions.add(region8);

		region9.setCompanyId(companyId);
		region9.setRegionName("上海市");
		region9.setRegionCode("QY0009");
		region9.setState(1);
		region9.setCreateTime(new Date());
		region9.setLongCode("QY0009");
		regions.add(region9);

		region10.setCompanyId(companyId);
		region10.setRegionName("江苏省");
		region10.setRegionCode("QY0010");
		region10.setState(1);
		region10.setCreateTime(new Date());
		region10.setLongCode("QY0010");
		regions.add(region10);

		region11.setCompanyId(companyId);
		region11.setRegionName("浙江省");
		region11.setRegionCode("QY0011");
		region11.setState(1);
		region11.setCreateTime(new Date());
		region11.setLongCode("QY0011");
		regions.add(region11);

		region12.setCompanyId(companyId);
		region12.setRegionName("安徽省");
		region12.setRegionCode("QY0012");
		region12.setState(1);
		region12.setCreateTime(new Date());
		region12.setLongCode("QY0012");
		regions.add(region12);

		region13.setCompanyId(companyId);
		region13.setRegionName("福建省");
		region13.setRegionCode("QY0013");
		region13.setState(1);
		region13.setCreateTime(new Date());
		region13.setLongCode("QY0013");
		regions.add(region13);

		region14.setCompanyId(companyId);
		region14.setRegionName("江西省");
		region14.setRegionCode("QY0014");
		region14.setState(1);
		region14.setCreateTime(new Date());
		region14.setLongCode("QY0014");
		regions.add(region14);

		region15.setCompanyId(companyId);
		region15.setRegionName("山东省");
		region15.setRegionCode("QY0015");
		region15.setState(1);
		region15.setCreateTime(new Date());
		region15.setLongCode("QY0015");
		regions.add(region15);

		region16.setCompanyId(companyId);
		region16.setRegionName("河南省");
		region16.setRegionCode("QY0016");
		region16.setState(1);
		region16.setCreateTime(new Date());
		region16.setLongCode("QY0016");
		regions.add(region16);

		region17.setCompanyId(companyId);
		region17.setRegionName("湖北省");
		region17.setRegionCode("QY0017");
		region17.setState(1);
		region17.setCreateTime(new Date());
		region17.setLongCode("QY0017");
		regions.add(region17);

		region18.setCompanyId(companyId);
		region18.setRegionName("湖南省");
		region18.setRegionCode("QY0018");
		region18.setState(1);
		region18.setCreateTime(new Date());
		region18.setLongCode("QY0018");
		regions.add(region18);

		region19.setCompanyId(companyId);
		region19.setRegionName("广东省");
		region19.setRegionCode("QY0019");
		region19.setState(1);
		region19.setCreateTime(new Date());
		region19.setLongCode("QY0019");
		regions.add(region19);

		region20.setCompanyId(companyId);
		region20.setRegionName("海南省");
		region20.setRegionCode("QY0020");
		region20.setState(1);
		region20.setCreateTime(new Date());
		region20.setLongCode("QY0020");
		regions.add(region15);

		region21.setCompanyId(companyId);
		region21.setRegionName("广西壮族自治区");
		region21.setRegionCode("QY0021");
		region21.setState(1);
		region21.setCreateTime(new Date());
		region21.setLongCode("QY0021");
		regions.add(region21);

		region22.setCompanyId(companyId);
		region22.setRegionName("甘肃省");
		region22.setRegionCode("QY0022");
		region22.setState(1);
		region22.setCreateTime(new Date());
		region22.setLongCode("QY0022");
		regions.add(region22);

		region23.setCompanyId(companyId);
		region23.setRegionName("山东省");
		region23.setRegionCode("QY0015");
		region23.setState(1);
		region23.setCreateTime(new Date());
		region23.setLongCode("QY0015");
		regions.add(region15);

		region23.setCompanyId(companyId);
		region23.setRegionName("陕西省");
		region23.setRegionCode("QY0023");
		region23.setState(1);
		region23.setCreateTime(new Date());
		region23.setLongCode("QY0023");
		regions.add(region23);

		region24.setCompanyId(companyId);
		region24.setRegionName("新疆维吾尔自治区");
		region24.setRegionCode("QY0024");
		region24.setState(1);
		region24.setCreateTime(new Date());
		region24.setLongCode("QY0024");
		regions.add(region24);

		region25.setCompanyId(companyId);
		region25.setRegionName("青海省");
		region25.setRegionCode("QY0025");
		region25.setState(1);
		region25.setCreateTime(new Date());
		region25.setLongCode("QY0025");
		regions.add(region25);

		region26.setCompanyId(companyId);
		region26.setRegionName("宁夏回族自治区");
		region26.setRegionCode("QY0026");
		region26.setState(1);
		region26.setCreateTime(new Date());
		region26.setLongCode("QY0026");
		regions.add(region26);

		region27.setCompanyId(companyId);
		region27.setRegionName("重庆市");
		region27.setRegionCode("QY0027");
		region27.setState(1);
		region27.setCreateTime(new Date());
		region27.setLongCode("QY0027");
		regions.add(region27);

		region28.setCompanyId(companyId);
		region28.setRegionName("四川省");
		region28.setRegionCode("QY0028");
		region28.setState(1);
		region28.setCreateTime(new Date());
		region28.setLongCode("QY0028");
		regions.add(region28);

		region29.setCompanyId(companyId);
		region29.setRegionName("贵州省");
		region29.setRegionCode("QY0029");
		region29.setState(1);
		region29.setCreateTime(new Date());
		region29.setLongCode("QY0029");
		regions.add(region29);

		region30.setCompanyId(companyId);
		region30.setRegionName("云南省");
		region30.setRegionCode("QY0030");
		region30.setState(1);
		region30.setCreateTime(new Date());
		region30.setLongCode("QY0030");
		regions.add(region30);

		region31.setCompanyId(companyId);
		region31.setRegionName("西藏自治区");
		region31.setRegionCode("QY0031");
		region31.setState(1);
		region31.setCreateTime(new Date());
		region31.setLongCode("QY0031");
		regions.add(region31);

		region32.setCompanyId(companyId);
		region32.setRegionName("台湾");
		region32.setRegionCode("QY0032");
		region32.setState(1);
		region32.setCreateTime(new Date());
		region32.setLongCode("QY0032");
		regions.add(region32);

		region33.setCompanyId(companyId);
		region33.setRegionName("澳门");
		region33.setRegionCode("QY0033");
		region33.setState(1);
		region33.setCreateTime(new Date());
		region33.setLongCode("QY0033");
		regions.add(region33);

		region34.setCompanyId(companyId);
		region34.setRegionName("香港");
		region34.setRegionCode("QY0034");
		region34.setState(1);
		region34.setCreateTime(new Date());
		region34.setLongCode("QY0034");
		regions.add(region34);

		try {
			initBasicInfoService.initBasicInfo(codingRules, templates, transportModes, regions, companyId);
		} catch (Exception e) {
			e.printStackTrace();
			res.put("flag", false);
			res.put("msg", "初始化失败!");
			return res;
		}
		res.put("flag", true);
		res.put("msg", "初始化完成!");
		return res;
	}
}
